﻿#if (!WINRT)

using System;
using nRoute.Components.Composition;
using nRoute.Controllers;
using nRoute.Utilities;

namespace nRoute.Mapping
{
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
    public class DefineControllerAttribute
        : MapControllerAttribute 
    {
        private const string CONTROLLER_MUSTBE_OFTYPE = "{0} type must be an implementation of the IController type.";

        private readonly Type _controllerType;

        public DefineControllerAttribute(string url, Type controllerType)
            : base(url)
        {
            Guard.ArgumentNotNull(controllerType, "controllerType");
            Guard.ArgumentIsType(controllerType, typeof(IController), "controllerType", CONTROLLER_MUSTBE_OFTYPE, controllerType.FullName);

            _controllerType = controllerType;
        }

#region Properties

        public Type ControllerType
        {
            get { return _controllerType; }
        }

#endregion

#region Overrides

        protected internal override IResourceLocator GetResourceLocator(Type targetType, ITypeBuilder typeBuilder)
        {
            // note we insert/switch the type
            return base.GetResourceLocator(this.ControllerType, typeBuilder);
        }

#endregion

    }
}

#endif